Page({
  data: {
    recommendList: []
  },
  async onShow() {
    const res = await wx.cloud.callFunction({ name: 'getOpenId' });
    const openid = res.result.openid;
    wx.cloud.callFunction({
      name: 'recommendStocks',
      data: { openid },
      success: res => {
        this.setData({ recommendList: res.result.result });
      }
    });
  },
  goToStockDetail(e) {
    const code = e.currentTarget.dataset.code;
    const name = e.currentTarget.dataset.name;
    wx.navigateTo({
      url: `/pages/stock/stock?name=${encodeURIComponent(name)}&code=${code}`
    });
  }
});
